#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for(register int i = (a);i <= (b);++i)
#define per(i,a,b) for(register int i = (a);i >= (b);--i)  
typedef long long ll;
typedef unsigned long long ull;
using std::string;using std::cin;using std::cout;

int _,a,b,cnt_x,cnt_y,w_x,w_y,ans,Ans,remain,tmp_y,tmp_x;

int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("in.in", "r", stdin);
    cin >> _;
    while(_--){
        Ans = 0;
        cin >> a >> b >> cnt_x >> cnt_y >> w_x >> w_y;
        if(a < b) std::swap(a,b);
        if(w_x > w_y) std::swap(cnt_x,cnt_y) , std::swap(w_x,w_y);
        for(register int i = 0;i * w_x <= a && i <= cnt_x;++i){
            ans = 0;
            remain = a - i * w_x;
            ans = i + std::min(cnt_y,remain / w_y);
            tmp_y = cnt_y - std::min(cnt_y,remain / w_y);
            tmp_x = cnt_x - i;
            ans += std::min(tmp_x,b / w_x);
            remain = b - std::min(tmp_x,b / w_x) * w_x;
            ans += std::min(tmp_y,remain / w_y);
            Ans = std::max(Ans,ans);
        }
        cout << Ans <<"\n";
    }
    return 0;
}